package main

import (
	"context"
	"git.900sui.cn/kc/base/utils"
	"git.900sui.cn/kc/kcgin"
	"git.900sui.cn/kc/kcgin/logs"
	"git.900sui.cn/kc/rabbitmq"
	"git.900sui.cn/kc/rpcinterface/client/reservation"
	reservation2 "git.900sui.cn/kc/rpcinterface/interface/reservation"
	"github.com/streadway/amqp"
	"strconv"
)

//预约的消费完成
func main() {
	rpcRecord := new(reservation.Record).Init()
	logs.Info("Environment Variable:MSF_ENV:", kcgin.KcConfig.RunMode)
	new(utils.KcLog).GetInstance(kcgin.AppConfig.String("reservation.log.reservationComplete"))
	err := rabbitmq.Rabbitmq.Consume(kcgin.AppConfig.String("reservation.queue.reservationComplete"), func(msg amqp.Delivery) {
		reservationId, err := strconv.Atoi(string(msg.Body))
		if err != nil{
			utils.Logerr.Printf("预约id转换成int失败，reservationId:%s, err:%s", string(msg.Body), err)
			return
		}
		args := reservation2.ModifyReservationParams{
			ReservationID: reservationId,
			Status:        reservation2.ReservationStatusCompleted,
		}
		reply := false
		err = rpcRecord.ChangeStatus(context.Background(), &args, &reply )
		if err != nil{
			utils.Logerr.Printf("预约id设为为处理成功失败，reservationId:%d, err:%s", reservationId, err)
		}
	})

	if err != nil {
		utils.Logerr.Printf("预约成功任务处理错误，err: %s", err.Error())
	}

}
